$(function () {
    findTeacher();
    $("#page").load("/html/page.html");
});

function findTeacher() {
    let result = myAjax('/d/daily/findTeacher', 'get', {});
    console.log(result);
    if (result.code === 200) {
        let html = "<option value='0'>全部</option>";
        for (let i = 0; i < result.data.length; i++) {
            html += '<option value="' + result.data[i].id + '">' + result.data[i].nickName + '</option>'
        }
        $("#classTeacher").html(html);
    }
}

function findAll() {
    let data = {
        name: $("#name").val(),
        classTeacher:$("#classTeacher").find("option:selected").text() ,
        type:$("#type").find("option:selected").val() ,
        username:localStorage.getItem("username"),
        pageSize: $.trim($("#pageSize").val()),
        pageNum: $.trim($("#pageNum").val()),
    }
    console.log(data);
    let result = myAjax('/d/daily/findAll','post',data);
    if (result.code===200){
        show(result.data.list);
        $("#pageCount").html(result.data.number);
    }else {
        layer.msg(result.message);
    }
}
function show(data) {
    let html = "";
    for (let i=0;i<data.length;i++){
        if (data[i].type===0){
            data[i].type ="未提交";
            html += '   <tr> ' +
                '  <td><input type="checkbox" name="isCheck" value="' + data[i].id + '">' + data[i].id + '</td>\n' +
                '        <td>' + data[i].name + '</td>\n' +
                '        <td>' + data[i].classTeacher + '</td>\n' +
                '        <td>' + data[i].coach + '</td>\n' +
                '        <td>' + data[i].writeTime + '</td>\n' +
                '        <td style="color: red">' + data[i].type + '</td>\n' +
                '        <td><input type="button" style="width: 80px;border-radius: 5px;' +
                'background-color: #b4c13e" value="编辑日报" onclick="edit(' + data[i].id + ')">' +
                '         <input type="button" style="width: 80px;border-radius: 5px;' +
                'background-color: #37905a" value="提交" onclick="submit(' + data[i].id + ')"></td>' +
                '    </tr>';
        }else if (data[i].type===1){
            data[i].type="已提交";
            html += '   <tr> ' +
                '  <td><input type="checkbox" name="isCheck" value="' + data[i].id + '">' + data[i].id + '</td>\n' +
                '        <td>' + data[i].name + '</td>\n' +
                '        <td>' + data[i].classTeacher + '</td>\n' +
                '        <td>' + data[i].coach + '</td>\n' +
                '        <td>' + data[i].writeTime + '</td>\n' +
                '        <td style="color: green">' + data[i].type + '</td>\n' +
                '        <td><input type="button" style="width: 80px;border-radius: 5px;' +
                'background-color: #d0c34b" value="审核进度" onclick="lookAudit(' + data[i].id + ')"></td>' +
                '    </tr>';
        }
    }
    $("#findAll").html(html);
}
layui.use('layer');

function edit(id) {
    sessionStorage.setItem("dailyId", id);
    //弹出一个页面层
    layer.open({
        type: 2,
        anim: 3,
        scrollbar: true,
        title: '编辑日报',
        area: ['800px', '750px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/daily/dailyEdit.html', 'no'],
    })
}
function newAdd(title, url) {
    layer.open({
        type: 2,
        anim: 1,
        scrollbar: true,
        title: title,
        area: ['800px', '750px'],
        shadeClose: true, //点击遮罩关闭
        content: [url, 'no'],
    })
}
function submit(id) {
 let result = myAjax('/d/daily/submit','post',{id:id});
 if (result.code===200){
     layer.msg("提交成功");
     location.assign('/html/daily/checkDaily.html')
 }else {
     layer.msg("提交审核失败");
 }
}
function lookAudit(id) {
    sessionStorage.setItem("dailyId",id);
    layer.open({
        type: 2,
        anim: 1,
        scrollbar: true,
        title: '审核进度',
        area: ['500px', '400px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/daily/auditReview.html', 'no'],
    })
}